package com.atguigu.yygh.common.utils;

import com.atguigu.yygh.common.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: Administrator
 * @date: 2023-02-06 10:23
 * @desc:
 */
//获取当前用户信息的工具类
public class AuthContextHolder {

    //获取当前用户的id
    public static Long getUserId(HttpServletRequest request) {
        //从header里获取token
        String token = request.getHeader("token");
        //jwt从token中获取userId
        Long userId = JwtHelper.getUserId(token);
        return userId;
    }

    //获取当前用户的名称
    public static String getUserName(HttpServletRequest request) {
        //从header里获取token
        String token = request.getHeader("token");
        //jwt从token中获取userId
        String userName = JwtHelper.getUserName(token);
        return userName;
    }

}
